<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        .box,
        .copy {
            position: absolute;
            left: 100px;
            top: 100px;
            width: 200px;
            height: 200px;
            background-color: cyan;
        }
    </style>

</head>

<body>
    <div class="box" draggable="true"></div>
</body>
<script>
    const box = document.querySelector('.box')
    class Drag {
        constructor(dom) {
            this.dom = dom
            this.dom.addEventListener('dragstart', this.start)
            this.dom.addEventListener('dragend', this.end)
        }
        start = (e) => {
            this.createElement()
            this.initX = e.x - this.dom.offsetLeft
            this.initY = e.y - this.dom.offsetTop

        }
        createElement() {
            this.div = document.createElement('div')
            this.div.setAttribute('class', 'copy')
        }
        end = (e) => {
            // console.log(e, 'end')
            this.div.style.left = (e.x - this.initX) + 'px'
            this.div.style.top = (e.y - this.initY) + 'px'
            document.body.appendChild(this.div)

        }
    }
    new Drag(box)
</script>

</html>